class StringIterator(object):

    def __init__(self, compressedString):
        """
        :type compressedString: str
        """
        self.s = compressedString
        self.count = 0
        self.val = None
        self.index = 0
        self.length = len(self.s)

    def next(self):
        """
        :rtype: str
        """
        if not self.count:
            if self.index < self.length:
                val = self.s[self.index]
                self.val = val
                left_index = self.index + 1
                right_index = left_index + 1
                while right_index < self.length and '0' <= self.s[right_index] <= '9':
                    right_index += 1
                self.count = int(self.s[left_index: right_index]) - 1
                self.index = right_index
            else:
                val = ' '
        else:
            val = self.val
            self.count -= 1
        return val

    def hasNext(self):
        """
        :rtype: bool
        """
        if self.count:
            return True
        else:
            if self.index < self.length:
                return True
            else:
                return False
